home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / human interface toolbox / fragment tool / fragmenttool.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  4.3 KB  |  219 lines

  1. /*
  2.     File:        FragmentTool.c
  3.  
  4.     Contains:    Main event loop and basic keyboard/mouse processing
  5.  
  6.     Written by: Chris White    
  7.  
  8.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/5/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #include <Memory.h>
  24. #include <AppleEvents.h>
  25. #include <Dialogs.h>
  26. #include <Devices.h>
  27. #include <Windows.h>
  28.  
  29. #define    __MAIN__
  30.  
  31.  
  32. #include "FragmentTool.h"
  33.  
  34. #include "Prototypes.h"
  35.  
  36. #if defined(powerc) && !defined(__MWERKS__) // MetroWerks declares "qd" in their runtime
  37.     QDGlobals    qd;
  38. #endif
  39.  
  40.  
  41.  
  42.  
  43. void main ( void );
  44. static void DoKey ( EventRecord*theEvent );
  45. static void DoMouseDown ( EventRecord* theEvent );
  46. static void EventLoop ( void );
  47.  
  48.  
  49.  
  50.  
  51. void main ( void )
  52. {
  53.     MaxApplZone ( );
  54.     
  55.     // We don't use too many more handles, so we onyl need to call
  56.     // MoreMasters a couple of times.
  57.     MoreMasters ( );
  58.     MoreMasters ( );
  59.     
  60.     
  61.     InitToolbox ( );                        // Init toolbox stuff
  62.     InitApplication ( );                    // Init application specific stuff
  63.     EventLoop ( );
  64.     
  65.     
  66.     return;
  67. }
  68.  
  69.  
  70.  
  71. static void EventLoop ( void )
  72. {
  73.     OSErr            theErr;
  74.     EventRecord        theEvent;
  75.     
  76.     
  77.     while ( !gQuit )
  78.     {
  79.         WaitNextEvent ( everyEvent, &theEvent, gSleepTime, nil );    
  80.         
  81.         switch ( theEvent.what )
  82.         {
  83.             case nullEvent:
  84.             {
  85.                 DialogRef    theDialog;
  86.                 
  87.                 theDialog = FrontWindow ( );
  88.                 if ( GetWindowType ( theDialog ) == kGetInfoWindowType )
  89.                     TEIdle ( ((DialogPeek) theDialog)->textH );
  90.             }
  91.             break;
  92.             
  93.             case mouseDown: 
  94.                 DoMouseDown ( &theEvent );
  95.             break;
  96.             
  97.             case keyDown:
  98.             case autoKey: 
  99.                 DoKey ( &theEvent );
  100.             break;
  101.             
  102.             case activateEvt: 
  103.                 DoActivate ( &theEvent );
  104.             break;
  105.             
  106.             case updateEvt:
  107.                 DoUpdate ( &theEvent );
  108.             break;
  109.             
  110.             case osEvt:
  111.                 if ( (theEvent.message >> 24) & suspendResumeMessage )    /* suspend or resume */
  112.                 {
  113.                     /* Modify the event record to look like an activate/deactivate event */
  114.                     theEvent.modifiers = theEvent.message; /* Copy suspend/resume flag */
  115.                     theEvent.message = (long) FrontWindow ( );    
  116.                     DoActivate ( &theEvent );
  117.                 }
  118.             break;
  119.             
  120.             case kHighLevelEvent:
  121.                 theErr = AEProcessAppleEvent ( &theEvent );
  122.             break;
  123.         }
  124.     }
  125.     
  126.     return;
  127.     
  128. } // EventLoop
  129.  
  130.  
  131.  
  132. static void DoMouseDown ( EventRecord* theEvent )
  133. {
  134.     Point            globalPt = theEvent->where;
  135.     int16            windowPart;
  136.     WindowRef        theWindow;
  137.     long            theMenu;
  138.     
  139.     
  140.     windowPart = FindWindow ( globalPt, &theWindow );
  141.     switch ( windowPart )
  142.     {
  143.         case inMenuBar: 
  144.             theMenu = MenuSelect ( globalPt );
  145.             MenuDispatch ( theMenu );
  146.         break;
  147.         
  148.         case inSysWindow:
  149.             // The SystemClick toolbox routine handles system events
  150.             SystemClick ( theEvent, theWindow );
  151.         break;
  152.         
  153.         case inGoAway: 
  154.             if ( TrackGoAway ( theWindow, theEvent->where ) )
  155.             {
  156.                 // Very easy to implement, and very useful on occasion
  157.                 if ( theEvent->modifiers & optionKey )
  158.                     DoCloseAllDocuments ( );
  159.                 else
  160.                     DoCloseDocument ( theWindow );
  161.             }
  162.         break;
  163.         
  164.         case inDrag:
  165.             DoDragWindow ( theWindow, theEvent );
  166.         break;
  167.  
  168.         case inGrow: 
  169.             DoGrowWindow ( theWindow, theEvent );
  170.         break;
  171.         
  172.         case inContent:
  173.             DoContentClick ( theWindow, theEvent );
  174.         break;
  175.  
  176.         case inZoomIn:
  177.         case inZoomOut: 
  178.             DoZoomWindow ( theWindow, theEvent, windowPart );
  179.         break;
  180.     }
  181.     
  182.     return;
  183.     
  184. } // DoMouseDown
  185.  
  186.  
  187.  
  188. static void DoKey ( EventRecord* theEvent )
  189. {
  190.     char keyPressed = (theEvent->message & charCodeMask);
  191.     
  192.     
  193.     if ( theEvent->modifiers & cmdKey )
  194.     {
  195.         // Command keys get handled by the menu handling routines
  196.         AdjustMenus ( );
  197.         MenuDispatch ( MenuKey ( keyPressed ) );
  198.     }
  199.     else
  200.     {
  201.         // Pass other key strokes to the dialog handling routines
  202.         int16        itemHit;
  203.         WindowRef    theWindow = FrontWindow ( );
  204.         
  205.         if ( IsMovableModal ( theWindow ) )
  206.         {
  207.             if ( DialogSelect ( theEvent, &theWindow, &itemHit ) )
  208.                 DoDialogItemHit ( theWindow, itemHit );
  209.         }
  210.     }
  211.     
  212.     return;
  213.     
  214. } // DoKey
  215.  
  216.  
  217.  
  218.  
  219.